﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="ReservationWater.aspx.cs" Inherits="WeChat.WaterMng.ReservationWater" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <link href="../layui/css/layui.css" rel="stylesheet" />
    <script src="../layui/laydate/laydate.js"></script>
    <script src="../Scripts/jquery-2.1.1.min.js"></script>
    <title>预约水控</title>
</head>
<body>
    <div class="layui-form">
        <div class="layui-form-item">

            <div class="layui-inline" style="display:none">
                <label class="layui-form-label">卡号：</label>
                <span class="layui-form-span" id="rfkh" style="display: block; padding-top: 10px;"><%=rfkh %></span>
            </div>
            <br/>
            <br/>
            <div class="layui-inline">
                <label class="layui-form-label">开始时间：</label>
                <div class="layui-input-inline">                
                    <input type="text" class="layui-input" id="beginTime" placeholder="yyyy-MM-dd HH:mm:ss" />
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label">结束时间：</label>
                <div class="layui-input-inline">
                    <input type="text" class="layui-input" id="endTime" placeholder="yyyy-MM-dd HH:mm:ss" />
                </div>
            </div>

     <%--       <div class="layui-inline">
                <label class="layui-form-label">预约位置：</label>
                <div class="layui-input-block">
                    <select name="canteen" id="canteen" class="layui-form" lay-verify="required" style="display: block; width: 50%;">
                    </select>
                </div>

            </div>--%>


            <div class="layui-inline">
               <label class="layui-form-label">预约位置：</label>
                <div class="layui-input-inline">
                    <select   name="canteen" id="canteen"  lay-verify="required" lay-search="">
                        <option value="">直接选择或搜索选择</option>
                    
            
                    </select>
                </div>
            </div>


            <div class="layui-btn" id="submit" style="justify-content: center; align-items: center; align-content: center; display: flex;">点此预约</div>
        </div>
    </div>
     <script src="../layui/layui.js"></script>
    <script>

        $(document).ready(function () {

            let openid = "<%=openid%>";

            $.ajax({
                type: "post",
                url: "../MenuReserveHandler.ashx",
                dataType: "json",
                async: false,
                data: { openid: openid, funcName: 'getCanteen' },
                success: function (data) {
                    if (data == null || data == "") {
                        alert("请先添加位置！");
                    } else {
                        var PowerValidate = $.parseJSON(data.baseInfos);
                        if (PowerValidate[0]["qx"] > 0) {

                            var canteen_arr = $.parseJSON(data.baseInfo);
                            $("#canteen").empty();
                            //for (var i = 0; i < canteen_arr.length; i++) {
                            //    $("#canteen").append("<option  value=" + canteen_arr[i]["canteen_name"] + ">" + canteen_arr[i]["canteen_name"] + "</option>");

                            //}


                            layui.use(['jquery', 'form'], function () {
                                var $ = layui.jquery, form = layui.form;
                                $("#canteen").append("<option  value=''>直接选择或搜索选择</option>");
                                for (var i = 0; i < canteen_arr.length; i++) {
                                    $("#canteen").append("<option  value=" + canteen_arr[i]["canteen_name"] + ">" + canteen_arr[i]["canteen_name"] + "</option>");

                                }
                                // 添加完记得render下  否则不会刷新到页面中
                                form.render('select');
                            })



                        } else {
                            alert("此人卡类型无权限预约！");
                            window.location.href = " ../index.html ";
                        }

                    }


                }


            })




            
           
          


        });



        //前后若干天可选，这里以7天为例
        laydate.render({
            elem: '#test-limit2'
            , theme: '#009688'
            , min: 0
            , max: 7
        });
        ////限定可选时间
        //laydate.render({
        //    elem: '#beginTime'
        //    , theme: '#009688'
        //    , type: 'time'
        //    , min: '00:00:00'
        //    , max: '23:59:00'
        //    , format: 'HH:mm'
        //    , btns: ['clear', 'confirm']
        //});

        //laydate.render({
        //    elem: '#endTime'
        //    , theme: '#009688'
        //    , type: 'time'
        //    , min: '00:00:00'
        //    , max: '23:59:59'
        //    , format: 'HH:mm'
        //    , btns: ['clear', 'confirm']
        //});

        //日期时间选择器
        laydate.render({
            elem: '#beginTime'
            , type: 'datetime'
            , min: -0
            , max: 7
        });
        laydate.render({
            elem: '#endTime'
            , type: 'datetime'
            , min: -0
            , max: 7
        });
        //  $("").remove();


        $("#submit").click(function () {

            let rfkh = $("#rfkh").text();
            let bookDate = $("#test-limit2").val();
            let beginTime = $("#beginTime").val();
            let endTime = $("#endTime").val();
            let canteen = $("#canteen").val();
            if (rfkh == "" || bookDate == "" || beginTime == "" || endTime == "" || canteen == "") {
                alert("参数有误，提交前请检查参数！"); return false;
            }
            beginTime = beginTime.replace(/\-/g, '/');//ios16以前不支持'-'日期格式
            // if (new Date(bookDate.replace(/\-/g, '/') + " " + beginTime) > new Date(bookDate.replace(/\-/g, '/') + " " + endTime)) {
            if (new Date(beginTime) > new Date(endTime)) {
                alert("开始时间不能大于结束时间！"); return false;
            }
            if (new Date(beginTime) < new Date()) {
                alert("预约时间请大于当前系统时间！"); return false;
            }

            $.ajax({
                type: "post",
                url: "../WaterReserveHandler.ashx",
                dataType: "json",
                async: false,
                data: {
                    rfkh: rfkh,
                    bookDate: bookDate,
                    beginTime: beginTime,
                    endTime: endTime,
                    wz: canteen,
                    funcName: 'addReservedRecords'
                },
                success: function (data) {
                    if (data != null) {
                        if (data == "10000") {
                            alert("预定成功！");
                            window.location.href = "../index.html";

                        }
                        if (data == "10005") {
                            alert("预定失败！"); return false;
                        }


                    }


                }
            });




        });

    </script>
</body>
</html>
